package com.xquant.screen.controller;

import com.xquant.screen.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: huaiyu.gao -_- -_-
 * @Date: 2021/4/28 17:33
 */
@RestController
public class indexController {

    @Autowired
    private IndexService indexService;

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    @RequestMapping("/t")
    public List getInfo(String key) {
        Map map = new HashMap();
        map.put("key", key);
        List list = indexService.selectInfo(map);
        return list;
    }

    @RequestMapping("/news")
    public List getNews() {
        Map map = new HashMap();
        List list = indexService.selectNews(map);
        return list;
    }

    //取表头
    @RequestMapping("/tableHead/{type}")
    public List selectSingleInfo(@PathVariable String type) {
        Map map = new HashMap();
        List list = new ArrayList();
        map.put("key",type);
        Optional<ConcurrentHashMap> actualissueamount = Optional.ofNullable(indexService.getActualissueamount(map));
        String actualissueamountStr = "";
        String issueNumStr = "";
        Optional<ConcurrentHashMap> issue_num = Optional.ofNullable(indexService.getISSUE_NUM(map));
        if (actualissueamount.isPresent()){
             actualissueamountStr = actualissueamount.get().get("ACTUALISSUEAMOUNT").toString();
        }
        if (issue_num.isPresent()) {
            issueNumStr = issue_num.get().get("ISSUE_NUM").toString();
        }
        list.add(issueNumStr);
        list.add(actualissueamountStr);
        return list;
    }


    @RequestMapping("/selectBond/{type}")
    public List selectBond(@PathVariable String type) {
        Map map = new HashMap();
        map.put("key",type);
        List list = indexService.selectBond(map);
        return list;
    }

}
